//
//  SISSCooperationProgressManageCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/19.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSHouseCooperationProgressManageCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface SISSHouseCooperationProgressManageCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *agencyNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *markLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (weak, nonatomic) IBOutlet UILabel *communityAndPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *regionAreaHouseTypeLabel;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *houseTagLabels;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelsViewHeight;
@property (weak, nonatomic) IBOutlet UILabel *progressTagLabel;
@property (weak, nonatomic) IBOutlet UIButton *redDotButton;

@end
@implementation SISSHouseCooperationProgressManageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.markLabel.layer.borderWidth = 1;

    self.markLabel.layer.borderColor = COLOR(0x8998A5).CGColor;
    self.markLabel.layer.cornerRadius = 2;
    self.markLabel.layer.masksToBounds = YES;
}

- (void)setHouseCoopProgressModel:(SISSHouseCoopProgressModel *)houseCoopProgressModel {
    _houseCoopProgressModel = houseCoopProgressModel;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:houseCoopProgressModel.portrait] placeholderImage:[UIImage imageNamed:@"头像"]];
    self.agencyNameLabel.text = houseCoopProgressModel.name;
    self.markLabel.text = houseCoopProgressModel.type == 2 ? @" 发布方 " : @" 合作方 ";
    self.companyLabel.text = houseCoopProgressModel.organ_name;
    self.communityAndPriceLabel.text = [NSString stringWithFormat:@"%@ | %.f万",houseCoopProgressModel.neighbourhood,houseCoopProgressModel.price];
    self.regionAreaHouseTypeLabel.text = [NSString stringWithFormat:@"%@-%@ | %ld㎡ | %@",houseCoopProgressModel.region,houseCoopProgressModel.regionDetail,(long)houseCoopProgressModel.area,houseCoopProgressModel.houseType];
    
    if (houseCoopProgressModel.listTag.count > 0) {
        self.labelsViewHeight.constant = 30;
    } else {
        self.labelsViewHeight.constant = 1;
    }
    
    NSArray<UIColor *> *labelCololors = @[COLOR(0x33B189), COLOR(0xF76D81), COLOR(0x8E7FFF), COLOR(0x59ABFD), COLOR(0xE46B00)];
    
    for (UILabel *label in self.houseTagLabels) {
        
        label.hidden = YES;
    }
    
    for (int i = 0; i < houseCoopProgressModel.listTag.count; i++) {
        UILabel *label = self.houseTagLabels[i];
        if ([houseCoopProgressModel.listTag[i].tag isEqualToString:@""]) continue;
        label.hidden = NO;
        label.layer.borderWidth = 1;
        label.text = [NSString stringWithFormat:@" %@ ",houseCoopProgressModel.listTag[i].tag];
        NSInteger colorIndex = houseCoopProgressModel.listTag[i].color - 1;
        label.layer.borderColor = labelCololors[colorIndex].CGColor;
        label.textColor = labelCololors[colorIndex];
        label.layer.cornerRadius = 2;
        label.layer.masksToBounds = YES;
    }
    
    NSArray *progressArr = @[ @"上传合作协议", @"实地看房", @"上传居间合同", @"上买卖合同", @"服务评价", @"已完成"];
    self.redDotButton.hidden = !houseCoopProgressModel.has_news;
    NSInteger count = self.isHistory ? 2 : 1;
    if (houseCoopProgressModel.progress == 6) {
        count = 1;
    }
    self.progressTagLabel.text = progressArr[houseCoopProgressModel.progress - count];
}


/**
 咨询按钮点击事件
 */
- (IBAction)contactButtonClickAction:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(houseCooperationProgressManageCell:clickContactButton:)]) {
        [self.delegate houseCooperationProgressManageCell:self clickContactButton:sender];
    }
}


@end
